<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title id="play_manager">放映厅管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!--搜索条件区域-->
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="search-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startDate" id="startDate" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="endDate" id="endDate" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button  class="layui-btn layui-btn-warm"  lay-filter="data-reset-btn"><i class="layui-icon">&#xe666;</i> 重 置</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <!--表格区域-->
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <!--行工具栏-->
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-del" lay-event="cancel">撤档</a>
        </script>
    </div>
</div>
<script src="../../static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','layer','upload','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer;


        //日期控件
        laydate.render({
            elem: '#startDate' //指定元素
        });
        laydate.render({
            elem: '#endDate' //指定元素
        });

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '/play/list',
            toolbar: '#toolbarDemo',
            cols: [
                [
                {field: 'playId', width: 100, title: 'ID', sort: true,align: "center"},
                {field: 'film', title: '电影名称',templet:function (d) {
                            return d.film.sName;
                    }},
                {field: 'room', width: 135, title: '放映厅', align: "center",sort: true,templet:function (d) {
                            return d.room.roomName;
                    }},
                {field: 'money', width: 135, title: '价格',align: "center"},
                {field: 'playTime', title: '放映日期', sort: true,templet :"<div>{{layui.util.toDateString(d.playTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            done: function(res,curr,count){ //解决当一页的最后一个数据被删除后，不会跳转到前一页的问题
                //判断当前页码是否大于1且当前页数据量为0
                if(curr > 1 && res.data.length == 0){
                    var pageValue = curr - 1;
                    //刷新数据表格的数据
                    tableIns.reload({
                        page: {curr:pageValue}
                    })
                }
            }
        });

        // 监听模糊查询操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            tableIns.reload({
                page: {
                    curr: 1
                }
                , where: data.field
            });

            return false;
        });

        //监听重置操作
        form.on('click(data-reset-btn)',function () {
            $("#search-form").reset();
        });


        //监听行工具栏事件
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'cancel') {
                cancelById(data);

            }
        });
        function cancelById(data) {
            //提示用户是否确认撤档
            layer.confirm('确定要撤下[<span style="color:red">'+data.film.sName+'</span>]吗？',{icon:3,title:"提示"}, function (index) {
                //发送撤档
                $.post("/play/cancel", {"playId":data.playId},function (result) {
                    if (result.success){
                        //成功
                        layer.alert(result.message,{icon:1});
                        //刷新当前数据表格
                        tableIns.reload();
                    }else{
                        //提示
                        layer.alert(result.message,{icon:2})
                    }
                },"json");
                layer.close(index);
            });
        }
    });
</script>

</body>
</html>